from diffusers import AutoPipelineForImage2Image
import torch
from diffusers.utils import load_image


def generate_by_ipadapter():
    pipeline = AutoPipelineForImage2Image.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16).to("cuda")

    image = load_image("tmp/vermeer.jpg")
    ip_image = load_image("tmp/river.png")

    pipeline.load_ip_adapter("h94/IP-Adapter", subfolder="models", weight_name="ip-adapter_sd15.bin")
    generator = torch.Generator(device="cuda").manual_seed(3322)
    image = pipeline(
        prompt='best quality, high quality,forest', 
        image = image,
        ip_adapter_image=ip_image,
        num_inference_steps=50,
        generator=generator,
        strength=0.6,
    ).images[0]
    image.save("tmp/c08.png")

generate_by_ipadapter()    

